package com.easyapi.common.utils;

import com.easyapi.common.enums.api.InterfaceInfoEnum;
import com.easyapi.common.enums.datasource.DataSourceType;

import java.util.Objects;

/**
 * @author: javadadi
 * @Time: 11:14
 * @ClassName: ApiStatusUtil
 */
public class ApiStatusUtil {
    /**
     * 提交状态获取
     *
     * @param testStatus
     * @return
     */
    public static InterfaceInfoEnum getTestStatus(Integer testStatus) {
        if (Objects.equals(testStatus, InterfaceInfoEnum.UN_COMMIT.getCode())) {
            return InterfaceInfoEnum.UN_COMMIT;
        } else {
            return InterfaceInfoEnum.IS_COMMITED;
        }
    }

    /**
     * 获取api生产类型
     *
     * @param apiType
     * @return
     */
    public static InterfaceInfoEnum getApiType(Integer apiType) {
        if (Objects.equals(apiType, InterfaceInfoEnum.API_TYPE_GENERATOR.getCode())) {
            return InterfaceInfoEnum.API_TYPE_GENERATOR;
        } else {
            return InterfaceInfoEnum.API_TYPE_REGISTER;
        }
    }

    /**
     * 获取api状态
     *
     * @param apiStatus
     * @return
     */
    public static InterfaceInfoEnum getApiStatus(Integer apiStatus) {
        if (Objects.equals(apiStatus, InterfaceInfoEnum.API_STATUS_INIT.getCode())) {
            return InterfaceInfoEnum.API_STATUS_INIT;
        } else if (Objects.equals(apiStatus, InterfaceInfoEnum.API_STATUS_INIT_SUCCESS.getCode())) {
            return InterfaceInfoEnum.API_STATUS_INIT_SUCCESS;
        } else if (Objects.equals(apiStatus, InterfaceInfoEnum.API_STATUS_INIT_FAILED.getCode())) {
            return InterfaceInfoEnum.API_STATUS_INIT_FAILED;
        } else if (Objects.equals(apiStatus, InterfaceInfoEnum.API_STATUS_NORMAL.getCode())) {
            return InterfaceInfoEnum.API_STATUS_NORMAL;
        } else if (Objects.equals(apiStatus, InterfaceInfoEnum.API_STATUS_BIND.getCode())) {
            return InterfaceInfoEnum.API_STATUS_BIND;
        } else {
            return InterfaceInfoEnum.API_STATUS_OFFLINE;
        }
    }

    /**
     * 生成api 请求类型
     *
     * @param reqType
     * @return
     */
    public static InterfaceInfoEnum getReqType(Integer reqType) {
        if (Objects.equals(reqType, InterfaceInfoEnum.REQ_TYPE_GET.getCode())) {
            return InterfaceInfoEnum.REQ_TYPE_GET;
        } else {
            return InterfaceInfoEnum.REQ_TYPE_POST;
        }
    }

    /**
     * 获取参数配置模式
     *
     * @param paramConfigType
     * @return
     */
    public static InterfaceInfoEnum getParamConfigType(Integer paramConfigType) {
        if (Objects.equals(paramConfigType, InterfaceInfoEnum.PARAM_CFG_TYPE_GENERATOR.getCode())) {
            return InterfaceInfoEnum.PARAM_CFG_TYPE_GENERATOR;
        } else {
            return InterfaceInfoEnum.PARAM_CFG_TYPE_SQL;
        }
    }

    /**
     * 获取数据源类型
     *
     * @param datasourceType
     * @return
     */
    public static DataSourceType getDatasourceType(Integer datasourceType) {
        if (Objects.equals(datasourceType, DataSourceType.MYSQL.getDataSourceType())) {
            return DataSourceType.MYSQL;
        }
        return null;
    }

    /**
     * 获取过期周期
     * @param cacheExpirePeriod
     * @return
     */
    public static InterfaceInfoEnum getCacheExpirePeriod(Integer cacheExpirePeriod) {
        if (Objects.equals(cacheExpirePeriod, InterfaceInfoEnum.CACHE_EXPIRY_PERIOD_MIN.getCode())) {
            return InterfaceInfoEnum.CACHE_EXPIRY_PERIOD_MIN;
        } else if (Objects.equals(cacheExpirePeriod, InterfaceInfoEnum.CACHE_EXPIRY_PERIOD_HOUR.getCode())) {
            return InterfaceInfoEnum.CACHE_EXPIRY_PERIOD_HOUR;
        } else if (Objects.equals(cacheExpirePeriod, InterfaceInfoEnum.CACHE_EXPIRY_PERIOD_DAY.getCode())) {
            return InterfaceInfoEnum.CACHE_EXPIRY_PERIOD_DAY;
        } else if (Objects.equals(cacheExpirePeriod, InterfaceInfoEnum.CACHE_EXPIRY_PERIOD_WEEK.getCode())) {
            return InterfaceInfoEnum.CACHE_EXPIRY_PERIOD_WEEK;
        } else {
            return InterfaceInfoEnum.CACHE_EXPIRY_PERIOD_MONTH;
        }
    }
}
